<template>
	<view class="main">
		<view v-if='guidePages' class="swiper-item">
			<image :src="adImage" mode=" scaleToFill" class="adImage"></image>
			<view class="empty" @tap="guideAdMessage()"></view>
			<view class="jump-over" @tap="jumpAd()">{{ i18n.skip }}</view>
		</view>
		<code-elf-guide v-else></code-elf-guide>
	</view>
</template>

<script>
	import codeElfGuide from '@/components/code-elf-guide/code-elf-guide.vue'
	export default {
		components: {
			codeElfGuide,
		},
		data() {
			return {
				guidePages: true,
				adImage: '/static/font/lan.png',
				barWidth: 5,
				radius: 40,
				duration: 5,
				timer: ''
			}
		},
		computed: {
		  i18n() {
		    return this.$t('index')
		  }
		},
		onLoad() {
			this.loadExecution()
			this.timer = setTimeout(function() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			}, 5000)
		},
		onUnload() {
			if (this.timer) {
				clearTimeout(this.timer);
				this.timer = null;
			}
		},
		methods: {
			loadExecution: function() {
				/**
				 * 获取本地存储中launchFlag的值
				 * 若存在，说明不是首次启动，直接进入首页；
				 * 若不存在，说明是首次启动，进入引导页；
				 */
				try {
					// 获取本地存储中launchFlag标识
					const value = uni.getStorageSync('launchFlag');
					if (value) {
						this.guidePages = true
					} else {
						// launchFlag!=true显示引导页
						this.guidePages = false
					}
				} catch (e) {
					// error 
					uni.setStorage({
						key: 'launchFlag',
						data: true,
						success: function() {
							console.log('error时存储launchFlag');
						}
					});
					this.guidePages = true
				}
				return;
				uni.reLaunch({
					url: '/pages/index/index'
				});
			},
			jumpAd() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
				if (this.timer) {
					clearTimeout(this.timer);
					this.timer = null;
				}
			},
			guideAdMessage() {
				console.log("$$$$$$$$$$$")
			}
		}
	}
</script>

<style>
	page,
	.main {
		width: 100%;
		height: 100%;
	}

	.swiper-item {
		width: 100%;
		height: 100%;
		text-align: center;
		position: relative;
		display: flex;
		/* justify-content: center; */
		align-items: flex-end;
		flex-direction: column-reverse
	}

	.timing {
		position: fixed;
		right: 45upx;
		top: 125upx;
		font-size: 32upx;
		z-index: 999;
	}

	.adImage {
		width: 100%;
		height: 100%;
		pointer-events: auto;
		z-index: 100;
	}

	.jump-over,
	.experience {
		position: absolute;
		height: 60upx;
		line-height: 60upx;
		padding: 0 40upx;
		border-radius: 30upx;
		font-size: 32upx;
		color: #454343;
		border: 1px solid #454343;
		z-index: 999;
	}

	.jump-over {
		right: 45upx;
		top: 125upx;
	}
	.empty{
		position: fixed;
		width: 100%;
		height: 100%;
		z-index: 10;
	}
</style>
